home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / AIFF DSP v22 / plugin_src / sinegen.c < prev    next >
Text File  |  1995-01-30  |  1KB  |  53 lines

  1. /* generates a sine wave of user-specified frequency */
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <limits.h>
  6.  
  7. #include "plugin_specific.h"
  8. #include "aiff.h"
  9. #include "type_conversion.h"
  10. #include "sintab.h"
  11. #include "num_input_macros.h"
  12.  
  13. static short harm;
  14.  
  15. void init_process_sinegen( void ) {
  16.    if ( USHRT_MAX != 65535 )
  17.       err( "this plugin is based on the assumption of 2 byte shorts" );
  18.  
  19.    get_sintab(); /* get a 1st-quadrant sine wave table */
  20.  
  21.    /* set AIFF header info (all else is default) */
  22.    nh.chan = 1;
  23.    nh.wdsi = 16;
  24.    nh.framsiz = 2;
  25.    GET_NUM_P( "number of samples", "%ld", nh.fram );
  26.    GET_NUM_P( "sampling rate",     "%lg",  nh.rate );
  27.  
  28.    harm = getusrharm( nh.rate );
  29. }
  30.  
  31. void term_process_sinegen( void ) {
  32. }
  33.  
  34. void process_samdat_sinegen( long buflen ) {
  35.    register short *td, *endd, tphase, tharm;
  36.    static short phase = 0;
  37.    
  38.    td     = d;
  39.    tphase = phase;
  40.    tharm  = harm;
  41.    endd   = &td[buflen];
  42.  
  43.    do {
  44.       *td++ = sin_tab( tphase &= TABMASK );
  45.       tphase += tharm;
  46.    } while ( td < endd );
  47.    
  48.    phase = tphase;
  49. }
  50.  
  51. plugin_info plugin_sinegen = { init_process_sinegen,
  52.    term_process_sinegen, process_samdat_sinegen, 0, 1 };
  53.